package cn.lili.modules.grab.factory.adjunct;

import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.grab.GrabAdjunctParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 辅助工厂
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class GrabAdjunctFactory {

    private final List<GrabAdjunctService> adjunctServiceList;

    /**
     * 地址查询工厂
     *
     * @param grabParam  参数
     */
    public ResultMessage<Object> generateAreaFactory(GrabAdjunctParam grabParam) {
        GrabAdjunctService grabAdjunctService = adjunctServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAdjunctService.area(grabParam);
    }

    /**
     * 获取全部省市区工厂
     *
     * @param grabParam  参数
     */
    public ResultMessage<Object> generateRegionAllFactory(GrabAdjunctParam grabParam) {
        GrabAdjunctService grabAdjunctService = adjunctServiceList.stream().filter(service -> service.step().name().equals(grabParam.getCode())).findFirst().get();
        return grabAdjunctService.regionAll(grabParam);
    }
}
